import { createRouter, createWebHashHistory, createWebHistory } from "vue-router";

const routes = [
  {
    path: "/",
    component: () => import("../view/home/index.vue"),
    redirect: "home",
    meta: {
      title: "首页"
    }
  },
  {
    name: "home",
    path: "/home",
    component: () => import("../view/home/index.vue"),
    meta: {
      title: "首页"
    }
  },
  {
    name: "bindCard",
    path: "/bindCard",
    component: () => import("../view/bindCard/bindCard.vue"),
    meta: {
      title: "绑定银行卡"
    }
  },
  {
    name: "bankList",
    path: "/bankList",
    component: () => import("../view/bankList/bankList.vue"),
    meta: {
      title: "银行卡列表"
    }
  },
  {
    name: "formBank",
    path: "/formBank",
    component: () => import("../view/formBank/formBank.vue"),
    meta: {
      title: "银行卡列表"
    }
  },
  {
    name: "no_bindCard",
    path: "/no_bindCard",
    component: () => import("../view/no_bindCard/no_bindCard.vue"),
    meta: {
      title: "免输卡号绑卡"
    }
  },
  {
    name: "no_bindCardForm",
    path: "/no_bindCardForm",
    component: () => import("../view/no_bindCard/no_bindCardForm.vue"),
    meta: {
      title: "快捷绑卡页面"
    }
  },
  {
    name: "success",
    path: "/success",
    component: () => import("../view/success/success.vue"),
    meta: {
      title: "支付成功"
    }
  },
  {
    name: "orderTimeout",
    path: "/orderTimeout",
    component: () => import("../view/orderTimeout/orderTimeout.vue"),
    meta: {
      title: "订单超时"
    }
  },
  {
    name: "error",
    path: "/error",
    component: () => import("../view/error/error.vue"),
    meta: {
      title: "订单失败"
    }
  },
  {
    name: "fail",
    path: "/fail",
    component: () => import("../view/fail/fail.vue"),
    meta: {
      title: "请求失败"
    }
  },
  {
    name: "frontH5Notify",
    path: "/frontH5Notify",
    component: () => import("../view/frontH5Notify/frontH5Notify.vue"),
    meta: {
      title: ""
    }
  },
];

const router = createRouter({
  routes,
  history: createWebHashHistory(),
  // history: createWebHistory(),
});

router.beforeEach((to, from, next) => {
  const title = to.meta && to.meta.title;
  if (title) {
    document.title = title;
  }
  next();
});

export { router };
